package com.hzc.springchan.controller;

import com.hzc.springchan.annotation.CApi;
import com.hzc.springchan.bean.request.Request;
import com.hzc.springchan.bean.response.Response;
import com.hzc.springchan.enums.CResource;
import com.hzc.springchan.service.IRouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 内部使用工具控制器类
 * @author chen990627
 * @date 2022/10/19
 */
@RestController
@RequestMapping("/general")
@Api(value = "/general", description = "内部工具")
public class GeneralController extends BaseController {

    @Autowired
    private IRouteService routeService;

    /**
     * 自动生成实体类等代码
     *
     * @param request
     * @return
     */
    @PostMapping("/db_table")
    @CApi(resource = CResource.GENERIC_DB_TABLE, skipTokenCheck = true)
    @ApiOperation(value = "自动生成实体类相关代码", httpMethod = "POST", response = Map.class)
    @ApiImplicitParam(name = "request", value = "参数列表，有四个：" +
            "tableName：表名；" +
            "className：生成的类前缀，一般跟表名对应；" +
            "author：作者；" +
            "description：描述", required = true, paramType = "body")
    public Response genericDbTable(@RequestBody Request request) {
        return requestRoute(routeService);
    }
}
